package com.haibara.codesubmiteval.chain.userChain;

import cn.hutool.core.util.StrUtil;
import com.haibara.codesubmiteval.model.dto.user.UserAddRequest;
import com.haibara.codesubmiteval.model.entity.User;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 处理用户名的节点
 *
 * @Author: mengyu
 * @Date: 2025/4/28
 */
@Component
@Order(2)
public class UsernameDefaultValueHandler extends CreateUserDefaultValueHandler {
    @Override
    public void handleDefaultValue(User user, UserAddRequest userAddRequest) {
        Long id = userAddRequest.getId();
        String username = userAddRequest.getUsername();
        // 如果用户名未设定，则默认为学号
        if (StrUtil.isBlankIfStr(username)) {
            user.setUsername(id.toString());
        } else {
            user.setUsername(username);
        }
        if (next != null) next.handleDefaultValue(user, userAddRequest);
    }
}
